package com.example.androidxdemo.service

import android.app.Service
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothManager
import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import android.util.Log
import com.blankj.utilcode.util.ToastUtils

/**
 * @author : yaobing
 * @date   : 2020/7/30 18:59
 * @desc   :
 */
class TemCollectService: Service() {
    private var mBluetoothManager: BluetoothManager? = null
    private var mBluetoothAdapter: BluetoothAdapter? = null
    private val mBinder: IBinder = aaa()
    override fun onBind(intent: Intent?): IBinder? {
        return mBinder
    }

    internal inner class aaa : Binder() {
        fun bb(): TemCollectService {
            return this@TemCollectService
        }
    }

    companion object {
        private const val TAG = "TemCollectService"
    }

    fun initialize(): Boolean {
        if (mBluetoothManager == null) {
            mBluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
            if (mBluetoothManager == null) {
                Log.e(TAG, "Unable to initialize BluetoothManager.")
                return false
            }
        }
        mBluetoothAdapter = mBluetoothManager!!.adapter
        if (mBluetoothAdapter == null) {
            Log.e(TAG, "Unable to obtain a BluetoothAdapter.")
            return false
        }
        return true
    }

    fun connect(mDeviceAddress: String) {
        ToastUtils.showShort("连接设备")
    }
}